<!DOCTYPE html>
<html>

<head>
	<title>我的资料</title>
	<meta charset="utf-8" />
	<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
	<link rel="stylesheet" href="/js/bootstrap/css/bootstrap.min.css">
	<script src="/js/jquery/jquery.min.js"></script>
	<link rel="stylesheet" href="/css/font/css/font-awesome.min.css" />
	<script src="/js/plugins/jrender/jrender.min.js"></script>
    <script src="/js/plugins/dialog2/dialog.min.js"></script>
	<link rel="stylesheet" href="/css/reset.css" />
	<link rel="stylesheet" href="/css/myProfiles.css" />
    <link rel="stylesheet" href="/js/plugins/dialog2/dialog.css">
	<script src="/js/common.js"></script>

	<script>
        //取出共享的数据
        var id = getParams().id;
        var message;
        var user;
        var userId = JSON.parse(sessionStorage.getItem("user")).id;
		$(function () {
            console.log(id);

            // 将数据设置到数据中
            // $.get('/users/' + id,function (data) {
            //     console.log(data);
            //     user=data;
            //     $('.info').renderValues(data);
            //     sessionStorage.setItem("stranger",JSON.stringify(data));
            // });

            $.get('/messages/addFriendMessage',{userId:id,targetId:userId},function (data) {
                user = data.user;
                $('.info').renderValues(user);
                sessionStorage.setItem("stranger",JSON.stringify(user));
                message = data;
                $('#message').text(message.content.content);
                get_href($('#travels'));
                get_href($('#info'));
            });




            //发送私信/添加好友/拉入群聊
            $('.sendMassageBtn').click(function () {
                var message = $('#message').val() + "";
                console.log(message);
                var type = $(this).data('type');
                $.post('/messages',{'user.id':userId,'target.id':id,'content.content': message,type:type},function (data) {
                    console.log(data);
                    if(data.success){
                        $(document).dialog({
                            style:"IOS",
                            titleShow: false,
                            autoClose: 2000,
                            content: '信息发送成功',
                        });
                    }else{
                        $(document).dialog({
                            style:"IOS",
                            titleShow: false,
                            autoClose: 2000,
                            content: data.msg,
                        });
                    }
                });
            });
            
            $('.addFriendBtn').click(function () {
                $.post('/friends',{'user.id':message.user.id,'friend.id':message.target.id},function (data) {
					if(data.success){
                        $(document).dialog({
                            style:"IOS",
                            titleShow: false,
                            autoClose: 2000,
                            content: '好友添加成功'
                        });
					}else{
                        $(document).dialog({
                            style:"IOS",
                            titleShow: false,
                            autoClose: 2000,
                            content: data.msg
                        });
					}
                })
            })

        });

        function get_href(item) {
            $.ajax({
                type: "PUT",
                url: "/messages/batchMarkread",
                data: {"userId":message.user.id,"targetId":message.target.id,type:3},
                success: function(data){

                }
            });
            item.attr('href',item.data('href') + id);
        }

	</script>

</head>

<body>
	<div class="nav-search">
			<a href="javascript:window.history.go(-1);">
				<span><i class="fa fa-angle-left fa-2x" ></i></span>
			</a>
	</div>
	<hr/>
<div class="container">
	<div class="row info">
		<div class="col-2" style="margin-right: 25px;">
			<img  class="rounded-circle" render-src="headImgUrl">
		</div>
		<div class="col-8">
			<h5 render-html="nickName"></h5>
			<ul class="list-inline">
				<li class="list-inline-item"><small>常住地</small></li>
				<li class="list-inline-item" render-html="place"><small ></small></li>
				<li class="list-inline-item"><small>关注<span>0</span></small></li>
				<li class="list-inline-item"><small>粉丝<span>0</span></small></li>
			</ul>
		</div>
	</div>



</div>

<hr />

<div class="row link-box">
	<div class="col">
		<!--他的游记-->
		<a data-href="/friend/travels.html?id=" id="travels">
		<li class="list-inline-item"><i class="fa fa-book fa-2x"></i></li>
		<li class="list-inline-item">
		<h7>他的游记</h7>
		<small><span>每日都有新内容</span></small></li>
		</a>

	</div>
	<div class="col">
		<!--他的个人资料-->
		<ul class="list-inline">
			<a data-href="/friend/info.html?id=" id="info">
			<li class="list-inline-item"> <i class="fa fa-user fa-fw fa-2x"></i> </li>
			<li class="list-inline-item">
			<h7>他的信息</h7>
			<small>查看详细信息</small></li>
			</a>
		</ul>
	</div>
</div>
<hr />
    <div class="container info">
        <label>信息:</label><b></b><textarea class="form-control" rows="5" id="message"></textarea>
    </div>
	<!--个人资料的跳转页面-->
	<div class="d-flex setting" >
		<div class="p-2 flex-fill" style="text-align: center">
			<a href="/mine/editTravels.html">
				<button class="btn sendMassageBtn" data-type="4">
					拒绝邀请</button>
			</a>
		</div>
		<div class="p-2 flex-fill" style="text-align: center">
			<a href="javascript:;"><button class="btn addFriendBtn" data-type="3">同意加为好友</button>
			</a></div>
        <div class="p-2 flex-fill" style="text-align: center">
            <a href="javascript:;"><button class="btn sendMassageBtn" data-type="1">发送私信</button>
            </a></div>
	</div>


<!--<ul class="mainmenu">
	<li><a href="#" ><b><i class="fa fa-star fa-2x"></i></b><span>我的收藏</span></a></li>
	<li><a href="#" ><b><i class="fa fa-commenting-o fa-2x"></i></b><span>我的评论</span></a></li>

	<li><a href="#" ><b><i class="fa fa-list-ul fa-2x"></i></b><span>我的心愿单</span></a></li>
	<li><a href="#" ><b><i class="fa fa-bullhorn fa-2x"></i></b><span>我的消息</span></a></li>
	<li><a href="#" ><b><i class="fa fa-file-text fa-2x"></i></b><span>我的订单</span></a></li>
	<li><a href="#" ><b><i class="fa fa-briefcase fa-2x"></i></b><span>我的钱包</span></a></li>
</ul>-->

</body>

</html>